package com.zzptc.lhl.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.lhl.myapplication.entity.Cars;
import com.zzptc.lhl.myapplication.entity.Youjia;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // getcarInfo();
        getYoujiajiaInfo();
    }

    private void getYoujiajiaInfo() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/gnyj/")
                .build();
      YoujiaService youjiaService= retrofit.create(YoujiaService.class);
      Call<Youjia> call=youjiaService.getAll("e0106d4f036cf6d539ae0469d19545b2");
      call.enqueue(new Callback<Youjia>() {
          @Override
          public void onResponse(Call<Youjia> call, Response<Youjia> response) {
              Youjia youjia=response.body();
              Log.d(TAG, "onResponse: "+youjia.getResult().size());
          }

          @Override
          public void onFailure(Call<Youjia> call, Throwable t) {

          }
      });
    }

    private void getcarInfo() {
        Retrofit r=new Retrofit.Builder()
                .baseUrl("http://www.hnzzsgz.cn:5001/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        CarsService carsService=r.create(CarsService.class);
       Call<Cars> all = carsService.getAll();
       all.enqueue(new Callback<Cars>() {
           @Override
           public void onResponse(Call<Cars> call, Response<Cars> response) {
               Cars cars =response.body();
               Log.d(TAG, "onResponse: "+cars.getData().get(1).getCarno());
           }

           @Override
           public void onFailure(Call<Cars> call, Throwable t) {
               Log.d(TAG, "onFailure: "+t.getMessage());
           }
       });
    }
}
